<template>
	<view class="containt">
		<image src="@/static/img/jdsbj.png" mode="widthFix" class="imgbg"></image>
		<view class="listbox">
			<view class="displayFlex itembox" v-for="(item,index) in sortList" @click="jumppage('/pages/authenticateInfo/authenticateInfo',item)">
				<image v-if='item.pic.length>0' :src="`${baseimgURL}${item.pic}`" mode="aspectFit" class="headPhone"></image>
				<image v-else src="" mode="aspectFit" class="headPhone"></image>
				<view class="rightbox">
					<view class="title">{{item.name||'~~'}}</view>
					<view class="flex">
						<view class="mode" v-for="(item,index) in item.showTag" >{{item||'-'}}</view>
						<!-- <view class="mode">{{item.name||'鉴定培训师'}}</view>
						<view class="mode">{{item.name||'支持比图服务'}}</view> -->
					</view>
					<view class="flex info">
						<view class="viewbox">执业<span class="span">{{item.showYear||'-'}}</span>年</view>
						<view style="width: 2rpx;height: 16rpx;background: #CBCBCB;margin-right: 6rpx;"></view>
						<view class="viewbox">鉴定<span class="span">{{item.showorder||'-'}}</span>万次</view>
						<view style="width: 2rpx;height: 16rpx; background: #CBCBCB;margin-right: 6rpx;"></view>
						<view class="viewbox">好评率<span class="span">{{item.showfavorableRate||'-'}}</span>%</view>
					</view>
					<view class="Identify" @click.stop="jumppage('/pages/jianding/add',item)">鉴定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { onLoad, onPullDownRefresh , onReachBottom } from "@dcloudio/uni-app";
	// 鉴定模块接口引入
	import { ref,reactive,inject  } from "vue";
	import { baseimgURL } from '@/config'
	import { fetchAppraiser,fetchAppraiserSort } from "@/utils/api/authenticate";
	const baseimgurl = inject("$baseimgurl");
	const state = reactive({
	  baseimgurl: baseimgurl
	});
	const sortList = ref([])
	const pageNum = ref(1)
	const jumppage = (url:string,item:object) => {
	  uni.navigateTo({ url: url+'?item='+JSON.stringify(item)});
	};
	onLoad(() => {
	  getAppraiser()
	});
	onPullDownRefresh(() => {
		console.log("下拉刷新")
	})
	onReachBottom(() => {
		console.log("上拉加载更多")
		pullUp()
	})
	const pullUp = () =>{
		pageNum.value = pageNum.value + 1
		getAppraiser()
	}
	const getAppraiser = async(item: object)=>{
		//获取当天0点时间戳
		
		const data = {
			pageNum: pageNum.value,
			pageSize: 10,
			typeCode: 'Appraiser',
			query: {},
			
		}
		const res = await fetchAppraiserSort( data );
		res.data.list.forEach((item,index)=>{
			//获取鉴定师入行当天0点时间戳，计算入行距今多少天
			let jujinDay = beforePresentDay(item.practiceTime)
			let jujinYear = beforePresentYear(item.practiceTime)
			item.showYear = jujinYear
			item.showTag = item.tag?item.tag.split(","):''
			item.showfavorableRate = item.favorableRate.split('%')[0]
			switch(item.appraiseSpeed){
				case '1':
					item.detailShowOrder = addNumber(jujinDay,1,1)+parseInt(item.appraiseNum?item.appraiseNum:0)
					item.showorder = String((addNumber(jujinDay,1,1)+parseInt(item.appraiseNum?item.appraiseNum:0))/10000).replace(/^(.*\..{2}).*$/,"$1")
					break;
				case '2':
				    item.detailShowOrder = addNumber(jujinDay,1,2)+parseInt(item.appraiseNum?item.appraiseNum:0)
					item.showorder = String((addNumber(jujinDay,1,2)+parseInt(item.appraiseNum?item.appraiseNum:0))/10000).replace(/^(.*\..{2}).*$/,"$1")
					break;
				case '3':
					item.detailShowOrder = addNumber(jujinDay,3,1)+parseInt(item.appraiseNum?item.appraiseNum:0)
					item.showorder = String((addNumber(jujinDay,3,1)+parseInt(item.appraiseNum?item.appraiseNum:0))/10000).replace(/^(.*\..{2}).*$/,"$1")
					break;
				case '4':
					item.detailShowOrder = addNumber(jujinDay,2,1)+parseInt(item.appraiseNum?item.appraiseNum:0)
					item.showorder = String((addNumber(jujinDay,2,1)+parseInt(item.appraiseNum?item.appraiseNum:0))/10000).replace(/^(.*\..{2}).*$/,"$1")
					break;
				case '5':
					item.detailShowOrder = addNumber(jujinDay,1,3)+parseInt(item.appraiseNum?item.appraiseNum:0)
					item.showorder = String((addNumber(jujinDay,1,3)+parseInt(item.appraiseNum?item.appraiseNum:0))/10000).replace(/^(.*\..{2}).*$/,"$1")
					break;
				default:
			}
		})
		sortList.value = [...sortList.value, ...res.data.list]
		console.log(res.data.list,'qqqqq')
	}
	//距今多少天
	const beforePresentDay = (practiceTime:string)=> {
		//入行时间戳
		let rhTime = new Date(practiceTime).getTime()
		console.log(rhTime,'ss')
		//当前时间戳
		let currentDaytimestamp = Date.parse(new Date(new Date(myDate()).getTime()))
		return (currentDaytimestamp - rhTime)/86400000
	}
	//距今多少年
	const beforePresentYear = (practiceTime:string)=> {
		//入行时间戳
		let rhTime = new Date(practiceTime).getTime()
		console.log(rhTime,'ss')
		//当前时间戳
		let currentDaytimestamp = Date.parse(new Date(new Date(myDate()).getTime()))
		let jujinDay = (currentDaytimestamp - rhTime)/86400000
		return Math.floor(jujinDay / 365)
	}
	//自定义万能加鉴定次数
	const addNumber =(totalDay:number, sday:number, frequency:number)=>{
		console.log(Math.floor(totalDay/sday*frequency)+'次数') 
		return Math.floor(totalDay/sday*frequency)
	}
	
	//自定义获取日期函数
	const myDate = () =>{
	    var date= new Date();
	    return date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()
	}

	
</script>

<style lang="scss" scoped>
	.containt {
	  padding: 14rpx 20rpx;
	}
	.imgbg{
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		z-index: -1;
	}
	.listbox{
		margin-top: 228rpx;
	}
	.itembox{
		background: #FFFFFF;
		border-radius: 15rpx;
		margin-bottom: 15rpx;
	}
	.headPhone{
		width: 157rpx;
		height: 238rpx;
	}
	.rightbox{
		margin-left: 27rpx;
	}
	.title{
		font-size: 27rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #000000;
		line-height: 38rpx;
		margin-bottom: 11rpx;
		margin-top: 27rpx;
	}
	.mode{
		height: 33rpx;
		background: #F4F7FB;
		border-radius: 4rpx;
		font-size: 18rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #5D7698;
		line-height: 33rpx;
		margin-right: 9rpx;
		padding: 3rpx 7rpx;
	}
	.info{
		color:#999999;
		margin-top: 16rpx;
		align-items: center;
		.viewbox{
			font-size: 22rpx;
			font-weight: 400;
			color: #999999;
			line-height: 31rpx;
			margin-right: 6rpx;
			.span{
				color: #E6542B;
			}
		}
	}
	.Identify{
		width: 130rpx;
		height: 51rpx;
		background: #953B82;
		border-radius: 27rpx;
		font-size: 22rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 18rpx;
	}
</style>